# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple aarch64 -run-pass=aarch64-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s

...
---
name:            add_64_mask_32
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: add_64_mask_32
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC %binop_lhs(s64)
    ; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC %binop_rhs(s64)
    ; CHECK: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[TRUNC]], [[TRUNC1]]
    ; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[ADD]](s32)
    ; CHECK: $x0 = COPY [[ZEXT]](s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_32:_(s64) = G_CONSTANT i64 4294967295
    %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %mask_32
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            sub_64_mask_32
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: sub_64_mask_32
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC %binop_lhs(s64)
    ; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC %binop_rhs(s64)
    ; CHECK: [[SUB:%[0-9]+]]:_(s32) = G_SUB [[TRUNC]], [[TRUNC1]]
    ; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[SUB]](s32)
    ; CHECK: $x0 = COPY [[ZEXT]](s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_32:_(s64) = G_CONSTANT i64 4294967295
    %binop:_(s64) = G_SUB %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %mask_32
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            mul_64_mask_32
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: mul_64_mask_32
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC %binop_lhs(s64)
    ; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC %binop_rhs(s64)
    ; CHECK: [[MUL:%[0-9]+]]:_(s32) = G_MUL [[TRUNC]], [[TRUNC1]]
    ; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[MUL]](s32)
    ; CHECK: $x0 = COPY [[ZEXT]](s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_32:_(s64) = G_CONSTANT i64 4294967295
    %binop:_(s64) = G_MUL %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %mask_32
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            and_64_mask_32
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: and_64_mask_32
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC %binop_lhs(s64)
    ; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC %binop_rhs(s64)
    ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[TRUNC]], [[TRUNC1]]
    ; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[AND]](s32)
    ; CHECK: $x0 = COPY [[ZEXT]](s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_32:_(s64) = G_CONSTANT i64 4294967295
    %binop:_(s64) = G_AND %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %mask_32
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            or_64_mask_32
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: or_64_mask_32
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: %mask_32:_(s64) = G_CONSTANT i64 4294967295
    ; CHECK: %binop:_(s64) = G_SUB %binop_lhs, %binop_rhs
    ; CHECK: %and:_(s64) = G_OR %binop, %mask_32
    ; CHECK: $x0 = COPY %and(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_32:_(s64) = G_CONSTANT i64 4294967295
    %binop:_(s64) = G_SUB %binop_lhs, %binop_rhs
    %and:_(s64) = G_OR %binop, %mask_32
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            xor_64_mask_32
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: xor_64_mask_32
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC %binop_lhs(s64)
    ; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC %binop_rhs(s64)
    ; CHECK: [[XOR:%[0-9]+]]:_(s32) = G_XOR [[TRUNC]], [[TRUNC1]]
    ; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[XOR]](s32)
    ; CHECK: $x0 = COPY [[ZEXT]](s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_32:_(s64) = G_CONSTANT i64 4294967295
    %binop:_(s64) = G_XOR %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %mask_32
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            walk_thru_copy
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: walk_thru_copy
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC %binop_lhs(s64)
    ; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC %binop_rhs(s64)
    ; CHECK: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[TRUNC]], [[TRUNC1]]
    ; CHECK: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[ADD]](s32)
    ; CHECK: $x0 = COPY [[ZEXT]](s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_32:_(s64) = G_CONSTANT i64 4294967295
    %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    %copy:_(s64) = COPY %binop
    %and:_(s64) = G_AND %copy, %mask_32
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            dont_combine_zext_not_free_add_64_mask_16
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: dont_combine_zext_not_free_add_64_mask_16
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: %mask_16:_(s64) = G_CONSTANT i64 65535
    ; CHECK: %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    ; CHECK: %and:_(s64) = G_AND %binop, %mask_16
    ; CHECK: $x0 = COPY %and(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_16:_(s64) = G_CONSTANT i64 65535
    %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %mask_16
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            dont_combine_zext_not_free_add_64_mask_8
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: dont_combine_zext_not_free_add_64_mask_8
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: %mask_8:_(s64) = G_CONSTANT i64 255
    ; CHECK: %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    ; CHECK: %and:_(s64) = G_AND %binop, %mask_8
    ; CHECK: $x0 = COPY %and(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_8:_(s64) = G_CONSTANT i64 255
    %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %mask_8
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            dont_combine_not_a_mask
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: dont_combine_not_a_mask
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: %not_a_mask:_(s64) = G_CONSTANT i64 26
    ; CHECK: %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    ; CHECK: %and:_(s64) = G_AND %binop, %not_a_mask
    ; CHECK: $x0 = COPY %and(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %not_a_mask:_(s64) = G_CONSTANT i64 26
    %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %not_a_mask
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            dont_combine_more_than_one_use
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: dont_combine_more_than_one_use
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: %not_a_mask:_(s64) = G_CONSTANT i64 26
    ; CHECK: %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    ; CHECK: %and:_(s64) = G_AND %binop, %not_a_mask
    ; CHECK: %or:_(s64) = G_OR %and, %binop
    ; CHECK: $x0 = COPY %or(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %not_a_mask:_(s64) = G_CONSTANT i64 26
    %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %not_a_mask
    %or:_(s64) = G_OR %and, %binop
    $x0 = COPY %or(s64)
    RET_ReallyLR implicit $x0
...
---
name:            dont_combine_vector
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $q0, $q1
    ; CHECK-LABEL: name: dont_combine_vector
    ; CHECK: liveins: $q0, $q1
    ; CHECK: %binop_lhs:_(<2 x s64>) = COPY $q0
    ; CHECK: %binop_rhs:_(<2 x s64>) = COPY $q1
    ; CHECK: %mask_elt:_(s64) = G_CONSTANT i64 4294967295
    ; CHECK: %mask:_(<2 x s64>) = G_BUILD_VECTOR %mask_elt(s64), %mask_elt(s64)
    ; CHECK: %binop:_(<2 x s64>) = G_ADD %binop_lhs, %binop_rhs
    ; CHECK: %and:_(<2 x s64>) = G_AND %binop, %mask
    ; CHECK: $q0 = COPY %and(<2 x s64>)
    ; CHECK: RET_ReallyLR implicit $q0
    %binop_lhs:_(<2 x s64>) = COPY $q0
    %binop_rhs:_(<2 x s64>) = COPY $q1
    %mask_elt:_(s64) = G_CONSTANT i64 4294967295
    %mask:_(<2 x s64>) = G_BUILD_VECTOR %mask_elt, %mask_elt
    %binop:_(<2 x s64>) = G_ADD %binop_lhs, %binop_rhs
    %and:_(<2 x s64>) = G_AND %binop, %mask
    $q0 = COPY %and(<2 x s64>)
    RET_ReallyLR implicit $q0
...
---
name:            dont_combine_add_64_mask_64
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: dont_combine_add_64_mask_64
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %binop_lhs:_(s64) = COPY $x0
    ; CHECK: %binop_rhs:_(s64) = COPY $x1
    ; CHECK: %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    ; CHECK: $x0 = COPY %binop(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %binop_lhs:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_64:_(s64) = G_CONSTANT i64 18446744073709551615
    %binop:_(s64) = G_ADD %binop_lhs, %binop_rhs
    %and:_(s64) = G_AND %binop, %mask_64
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
...
---
name:            dont_combine_copy_from_physreg
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $x0, $x1
    ; CHECK-LABEL: name: dont_combine_copy_from_physreg
    ; CHECK: liveins: $x0, $x1
    ; CHECK: %copy_from_physreg:_(s64) = COPY $x0
    ; CHECK: %mask_32:_(s64) = G_CONSTANT i64 4294967295
    ; CHECK: %and:_(s64) = G_AND %copy_from_physreg, %mask_32
    ; CHECK: $x0 = COPY %and(s64)
    ; CHECK: RET_ReallyLR implicit $x0
    %copy_from_physreg:_(s64) = COPY $x0
    %binop_rhs:_(s64) = COPY $x1
    %mask_32:_(s64) = G_CONSTANT i64 4294967295
    %copy:_(s64) = COPY %copy_from_physreg
    %and:_(s64) = G_AND %copy, %mask_32
    $x0 = COPY %and(s64)
    RET_ReallyLR implicit $x0
